using System.Collections.Generic;
using NetProtocol.POD;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 编队数据
    /// </summary>
    public class LogicFormationData
    {
        /// <summary>
        /// 编队id
        /// </summary>
        public int formId;
        /// <summary>
        /// 编队名字
        /// </summary>
        public string formName;
        /// <summary>
        /// 编队英雄cid
        /// </summary>
        public int leaderHeroCid;
        /// <summary>
        /// 队长英雄唯一id（缓存，外部模块维护)
        /// </summary>
        public long leaderHeroId;
        /// <summary>
        /// pos -> heroId
        /// 未来hero可能来自助战系统
        /// </summary>
        public readonly Dictionary<int, LevelFormationHeroData> heroes = new Dictionary<int, LevelFormationHeroData>(5);

        public LogicFormationData(int formId)
        {
            this.formId = formId;
        }

        public LogicFormationData(FormationPOD formationPod)
        {
            this.formId = formationPod.formId;
            this.formName = formationPod.formName;
            this.leaderHeroCid = formationPod.captainHeroCid;
            foreach (KeyValuePair<int, FormationHeroPOD> pair in formationPod.heroes)
            {
                LevelFormationHeroData heroData = new LevelFormationHeroData(pair.Value);
                heroData.isBench = pair.Key >= LgLevelConst.FormationBenchIndexStart;
                heroes[pair.Key] = heroData;
            }
        }

        public void SyncData(FormationPOD formationPod)
        {
            this.formName = formationPod.formName;
            this.leaderHeroCid = formationPod.captainHeroCid;
            foreach (KeyValuePair<int, FormationHeroPOD> pair in formationPod.heroes)
            {
                LevelFormationHeroData formationHeroData = heroes[pair.Key];
                formationHeroData.id = pair.Value.id;
                formationHeroData.cid = pair.Value.cid;
            }
        }
    }

    /// <summary>
    /// 编队英雄数据
    /// </summary>
    public class LevelFormationHeroData
    {
        /// <summary>
        /// 英雄唯一id
        /// </summary>
        public long id;
        /// <summary>
        /// 英雄cid
        /// </summary>
        public int cid;
        /// <summary>
        /// 是否是替补位
        /// </summary>
        public bool isBench;
        /// <summary>
        /// 英雄数据缓存(外部模块维护)
        /// </summary>
        public LogicHeroData heroData;

        /// <summary>
        /// 是否有英雄上阵
        /// </summary>
        public bool HasHero => cid > 0;

        public LevelFormationHeroData(FormationHeroPOD formHeroPOD)
        {
            this.id = formHeroPOD.id;
            this.cid = formHeroPOD.cid;
        }
    }
}